// pages/orderDesc/orderDesc.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    state: 1,
    list:[],
    order:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  sendPl: function (e) {
    let that = this;

    let id = e.target.dataset.id;
    wx.navigateTo({
      url: '../release_evaluation/release_evaluation?id=' + id
    });

  },

  allCount() {
    let num = 0
    let list = this.data.list

    if (list.length) {
      list.map((item, i) => {
        num += Number(item.goods_number)
      })
    }
    this.setData({
      allCount: num
    })
  },
  copy:function(){
    var that = this;
    wx.setClipboardData({
      data: that.data.order.invoice_no,
      success:function(res){
        wx.showToast({
          title: '复制成功',
          icon: 'success',
          mask: true,
        })
      }

    })
  },

  onLoad: function (options) {
    let that = this
    let proimgUrl = app.globalData.url.replace('mobile/', '')

    this.setData({
      url: app.globalData.url,
      proimgUrl: proimgUrl,
      order_id: options.id
    })
    wx.request({
      url: app.globalData.url + 'ziyu.php?Action=order_detail&order_id=' + options.id,

      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        console.log(res)
        that.setData({
          order: res.data.order,
          list: res.data.goods_list,
          biaoti: res.data.biaoti
        })

        switch (that.data.biaoti) {
          case '待发货':
            that.setData({
              state: 1
            })
            break
          case '已发货':
            that.setData({
              state: 3
            })
            break
          case '已完成':
            that.setData({
              state: 4
            })
            break
        }


        that.allCount()
      }

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})